﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fadd.InversionOfControl;
using Xunit;

namespace Fadd.Test.InversionOfControl
{
    public class LightWeightIocTest
    {
        private LightWeightIoc _container = new LightWeightIoc();

        [Fact]
        public void TestContainer()
        {
            _container.Register<ISimple, Simple>();
            _container.Register<OneDependency, OneDependency>();
            var instance = _container.Resolve<OneDependency>();
            var instance2 = _container.Resolve<OneDependency>();
            Assert.Same(instance2, instance);
        }

        [Fact]
        public void TestNested()
        {
            _container.Register<ISimple, Simple>();
            _container.Register<OneDependency, OneDependency>();
            _container.Register<NestedDependencies, NestedDependencies>();
            Assert.NotNull(_container.Resolve<NestedDependencies>());
            
        }

        [Fact]
        public void NotFound()
        {
            Assert.Null(_container.Resolve<LightWeightIocTest>());
        }
    }

    public interface ISimple
    {}

    public class Simple : ISimple
    {
        
    }

    public class OneDependency
    {
        public OneDependency(ISimple simple)
        {
            
        }
    }

    public class NestedDependencies
    {
        public NestedDependencies(OneDependency one)
        {
            
        }
        
    }
}


